import { Badge, Button, Table, Tag } from 'antd';
import { useState, useEffect, useRef } from 'react'
import dayjs from 'dayjs';
import { EnvironmentOutlined } from '@ant-design/icons';
import JcyjApi from '../../../../../../../utils/apis/JcyjApi';
import ScrollTable from '../../../../../../common/ScrollTable';
import DangerDel from '../DangerDel';
export default function TypeList(props) {
    const { typeId, typeName } = props;
    const [page, setPage] = useState(1);
    const [total, setTotal] = useState(0);
    const [datas, setDatas] = useState([]);
    const [loading, setLoading] = useState();

    const [refreshFlag, setRefreshFlag] = useState({});

    const {currentDelItem, setCurrentDelItem,data,setData} = props;
    
   
    useEffect(() => {
        setLoading(true);
        JcyjApi.TqList({ "type": "预警"}).then(resp => {
            console.log("@!23",resp)
            setDatas(resp.rows);
            // setTotal(resp.total)
        }).finally(e => {
            setLoading(false);
        })
    }, [typeName, page, refreshFlag]);

    const rootRef = useRef();

    const columns = [{
        title: '时间',
        dataIndex: 'id',
        width: 140
    }, {
        title: '标题',
        dataIndex: 'title',
        width: 300,
        render: (text) => {
            return text
        }
    },
    {
        title: '详情',
        dataIndex: 'url',
        width: 80,
        render: (text, record) => {
            return <Button type="link" href={record.url} onClick={e => {
    
            }}>详情 </Button>
            

        }
    },
    // {
    //     title: '操作',
    //     dataIndex: 'isfb',
    //     width: 160,
    //     render: (text, record) => {
    //         return <Button type="link"onClick={e => {
    //             setCurrentDelItem(record)
    //             //console.log(typeof record,record)

    //         }}>待办任务</Button>
    //     }
    // }, {
    //     title: '其他',
    //     dataIndex: 'yjxxnr',
    //     ellipsis: true
    // }
];

    return <div style={{
        // marginTop: -10,
        height: 285,
        overflow: "hidden",
        padding: 8
    }} ref={rootRef}>
        {/* <div style={{
            paddingBottom: 8
        }}>
            <Button size="small" type="primary">统计分析</Button>
        </div> */}
        <ScrollTable
            parentNode={rootRef.current}
            bordered
            loading={loading}
            size='small'
            columns={columns}
            dataSource={datas}
            pagination={{
                current: page,
                total: total,
                onChange: (page) => {
                    setPage(page)
                }
            }}
            rowClassName={(record, index) => {
                if (index % 2 === 0) {
                    return 'own-row'
                }
            }}
        ></ScrollTable>
        <DangerDel item={currentDelItem} onCancel={e => {
            setCurrentDelItem(null);
        }} onOk={e => {
            setRefreshFlag({});
            setCurrentDelItem(null);
        }} data={data} setData={setData}/>
    </div>;
}